// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EntLibContrib.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace EntLibContrib.Validation.Tests.Validators
{
    /// <summary>
    /// Tests <see cref="ObjectValidator"/>.
    /// </summary>
    [TestClass]
    public class ObjectValidatorFixture
    {
        [TestMethod]
        public void ReturnsSuccessForValidObject()
        {
            ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>();
            ValidationResults validationResults = validator.Validate(new TestTarget("test"));

            Assert.IsTrue(validationResults.IsValid);
        }

        [TestMethod]
        public void ReturnsFailureForInvalidObject()
        {
            ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>();
            ValidationResults validationResults = validator.Validate(new TestTarget(null));

            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Test target for this fixture.
        /// </summary>
        public class TestTarget
        {
            public TestTarget(string value) 
            { 
                s = value; 
            }

            [NotNullValidator()]
            public string s;
        }
    }
}
